package com.niit.servlet;

import com.niit.domain.News;
import com.niit.service.INewsService;
import com.niit.service.impl.NewsServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet(name = "NewsServlet", value = "/NewsServlet")
public class NewsServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        INewsService ins=new NewsServiceImpl();
        List<News> newsList=ins.newsService(5);
        //将list集合存放进session
        HttpSession newSession=request.getSession();
        newSession.setAttribute("newsList",newsList);

        List<News> newsList1=ins.newsService2(5);
        //将list集合存放进session
        HttpSession newSession1=request.getSession();
        newSession.setAttribute("newsList1",newsList1);

        List<News> newsList2=ins.newsService3(5);
        //将list集合存放进session
        HttpSession newSession2=request.getSession();
        newSession.setAttribute("newsList2",newsList2);
        //重定向
        response.sendRedirect("index.jsp");
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
